<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        百度 <input @input='input1' type="text" v-model='msg'>
        <button @click='btn1'>搜索</button>
        <ul v-show='flag'>
            <li v-bind:key='index' v-for="(item,index) in lists">
                {{item}}
            </li>
        </ul>
        <ul>
            <li v-bind:key='index' v-for="(item,index) in newss">
                {{item}}
            </li>
        </ul>

    </div>


    <script>

        var app = new Vue({
            el: '#app',
            data: {
                lists: [],
                index2: 1,
                msg: ''
            },
            // vue 侦听器 可以侦听数据变化 
            watch:{
                msg(value) {
                    console.log('进来watch里面了')
                    if(this.msg == '') {
                        this.lists = []
                    }
                }
            },
            methods: {
                btn1() {
                    if (this.msg == '水果') {
                        this.lists = ['苹果', '香蕉', '西瓜', '芒果']
                    }
                },
                input1() {
                    console.log('input1')
                    var time1 = null

                    clearTimeout(time1)


                    time1 = setTimeout(() => {
                        // 换成axios请求  
                        axios({
                        url: 'http://localhost:5003/httpvue/a',
                        method: 'get'
                    }).then(res => {
                        console.log(res)
                        this.city = res.data.msg
                    })
                        // if (this.msg == '吴') {
                        //     this.lists = ['吴亦凡事件', '吴亦凡国籍', '吴亦凡回应']
                        // } else if (this.msg == '吴亦') {
                        //     this.lists = ['吴亦凡微博', '吴亦凡解约', '吴亦凡风波']
                        // } else if (this.msg == '吴亦凡') {
                        //     this.lists = ['3333', '吴3333', '3333']
                        // }
                    }, 3000);




                }
            }
        })



    </script>
</body>

</html>